home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libimp
/
impError.c.z
/
impError.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
5KB
|
205 lines
/**************************************************************************
*
* Copyright (c) 1993 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: impError.c
*
* Description: Error handling routines and error string table.
*
**************************************************************************/
#ident "$Revision: 1.6 $"
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "impI.h"
/* Error message structure. Each entry contains a message catalog token
* and a default message.
*/
typedef struct {
char *catToken;
char *defMsg;
} ErrorMessage;
/* Global error variables */
int IMPerrno;
/*
* Error string table. The error codes are indices into this table
* after IMP_ERR_BASE has been subtracted from the code.
*/
static ErrorMessage errorTable[] = {
/* 0 */ {
_SGI_LIBIMP_ERR_READWRITE,
"read/write mode not supported"
},
/* 1 */ {
_SGI_LIBIMP_ERR_MEMALLOC,
"could not allocate memory"
},
/* 2 */ {
_SGI_LIBIMP_ERR_BADMAGIC,
"bad magic number - file may not be image file"
},
/* 3 */ {
_SGI_LIBIMP_ERR_BADRASTER,
"unreconized raster encoding"
},
/* 4 */ {
_SGI_LIBIMP_ERR_BADIMAGE,
"unreconized image type"
},
/* 5 */ {
_SGI_LIBIMP_ERR_BADROW,
"row or channel number out of range"
},
/* 6 */ {
_SGI_LIBIMP_ERR_BADDIM,
"image dimension out of range"
},
/* 7 */ {
_SGI_LIBIMP_ERR_READFLAG,
"image not opened for reading"
},
/* 8 */ {
_SGI_LIBIMP_ERR_BADBPP,
"unsupported bytes per pixel value"
},
/* 9 */ {
_SGI_LIBIMP_ERR_WRITEFLAG,
"image not opened for writing"
},
/* 10 */ {
_SGI_LIBIMP_ERR_READROW,
"read row function failed"
},
/* 11 */ {
_SGI_LIBIMP_ERR_SHORTREAD,
"less data read than expected"
},
/* 12 */ {
_SGI_LIBIMP_ERR_SHORTWRITE,
"unable to write all data"
},
/* 13 */ {
_SGI_LIBIMP_ERR_BADFD,
"invalid file descriptor"
},
/* 14 */ {
_SGI_LIBIMP_ERR_SEEK,
"cannot seek on file descriptor"
},
/* 15 */ {
_SGI_LIBIMP_ERR_NOWRITE,
"write mode not allowed"
},
};
static int nerr = sizeof(errorTable)/sizeof(ErrorMessage);
/**************************************************************************
*
* Function: impPerror
*
* Description: Similar to the C function perror, this function produces
* a message on the standard error output, describing the last error
* encountered during an IMP function call. The arguement s is printed
* first, then a colon and a blank, then the error message and a
* new-line. If s="" then the colon and blank are not printed.
*
* The function uses the global variable IMPerrno as an index into
* the error stringu table. The values for IMPerrno are contained in
* imp.h.
*
* Parameters:
* str (I) - User supplied error string to prepend on the error string
*
* Return: none
*
**************************************************************************/
void impPerror(const char *str)
{
if (str && strlen(str)) {
(void)fprintf(stderr, "%s: %s\n", str, impErrorString(IMPerrno));
} else {
(void)fprintf(stderr, "%s\n", impErrorString(IMPerrno));
}
}
/**************************************************************************
*
* Function: impErrorString
*
* Description: Returns a pointer to the error string that corresponds
* to the current value of the specified error variable. Note
* that we look in both the system error string table and our own
* depending on that value of the error variable.
*
* Parameters:
* errCode (I) - error code
*
* Return: Pointer to error string table. This pointer is to static
* storage and should not be freed.
*
**************************************************************************/
char* impErrorString(int errCode)
{
static char buf[128];
register int errInd;
/*
* First check whether this is a system (i.e. errno) error code
*/
if (errCode <= LASTERRNO)
return strerror(errCode);
/*
* Check if it is a valid IMP error code
*/
errInd = errCode - IMP_ERR_BASE;
if (errInd >= 0 && errInd < nerr)
return gettxt(errorTable[errInd].catToken, errorTable[errInd].defMsg);
/*
* Don't know what it is
*/
(void)sprintf(buf, gettxt(_SGI_LIBIMP_UNKNOWN_ERROR, "error code %d"),
errCode);
return buf;
}